package com.mujin.keji.collectionsystem.module.mypager.adapter;

import android.app.Activity;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.mujin.keji.collectionsystem.R;
import com.mujin.keji.collectionsystem.listeners.CustomItemClickListener;
import com.mujin.keji.collectionsystem.module.mypager.dto.VersionListDto;
import com.mujin.keji.collectionsystem.module.outboundtask.dto.BoundTaskDto;

import java.util.List;


/**
 * 历史任务列表适配器
 *
 * @author weishixiong
 * @Time 2018-03-21
 */

public class VersionListAdapter extends RecyclerView.Adapter<VersionListAdapter.ViewHolder> {
    private Activity mContext;
    private List<VersionListDto> datas;
    private CustomItemClickListener listener;

    public VersionListAdapter(Activity context, List<VersionListDto> datas, CustomItemClickListener listener) {
        mContext = context;
        this.datas = datas;
        this.listener = listener;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_version, parent, false);
        ViewHolder viewHolder = new ViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(final ViewHolder holder, final int position) {
        holder.tvVersionTitle.setText(datas.get(position).getVersionCode());
        holder.tvVersionContent.setText("该版本于" + datas.get(position).getUpdateTime() + "更新");
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                listener.onItemClick(holder.itemView, position);
            }
        });
    }

    @Override
    public int getItemCount() {
        return datas == null ? 0 : datas.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        private TextView tvVersionTitle;
        private TextView tvVersionContent;
        private View itemView;

        public ViewHolder(View itemView) {
            super(itemView);
            this.itemView = itemView;
            tvVersionTitle = (TextView) itemView.findViewById(R.id.tv_version_title);
            tvVersionContent = (TextView) itemView.findViewById(R.id.tv_version_content);
        }

    }
}
